<template>
    <DataList 
    :cate="cate" 
    :cols="cols" 
    :name="name"
    :excelHeader="excelHeader"
    skipExcelNumber="2"
    />
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import linq from "linq"
import { addShjz, deleteShjz, updateShjz, getShjz,bulkAddShjz } from "@/api/社会评价.js";
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A9-3社会（准）捐赠情况表",
      name:"9.3 社会捐赠情况",
      excelHeader:{B3:"捐赠单位",C3:"捐赠项目",D3:"捐赠日期（年月）",E3:"捐赠性质",F3:"捐赠价值（万元）"},
      cols: [
        { prop: "JZDW", label: "捐赠单位" },
        { prop: "JZXM", label: "捐赠项目名称(全称)" },
        { prop: "JZRQ", label: "捐赠日期(年月)" },
        { prop: "XZ_JZXZ", label: "捐赠性质" },
        { prop: "SHJZJE", label: "捐赠价值(万元)" }
      ]
    };
  },
  methods: {
    getSummaries(list){
      const sums = []
         this.cols.forEach((column, index) => {
            sums[index]=""
        })
        sums[0]="合计";
        sums[6]= "单位数:"+linq.from(list).count("$.JZDW")
        sums[7]= "项目数:"+linq.from(list).count("$.JZXM")
        sums[10]= "合计:"+linq.from(list).sum("$.SHJZJE")
        sums[11]= "通过:"+linq.from(list).where("$.审核状态=='通过'").count()
        sums[11]+= ",待审核:"+linq.from(list).where("$.审核状态=='待审核'").count()
        sums[11]+= ",不通过:"+linq.from(list).where("$.审核状态=='不通过'").count()
        return sums;
    },
     check(array,list) {
     return new Promise(async (resolve,reject)=>{
       resolve();
     })
 },
    async fetchData() {
      var user = getUser();
      var datas = await getShjz(user.XXID,user.CJPC);
      return datas;
    },
    onadd(model) {
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
         
        console.log(JSON.stringify(temp));
        var model = await addShjz(temp);
        resolve(model);
      })
    },
    async bulkAdd(array){
      await bulkAddShjz({Xsjy:array});
    },
    onupdate(model) {
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await updateShjz(temp);
          resolve(model);
      })
    },
    ondelete(model) {
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
      
      await deleteShjz(temp);
      resolve();
      })
    }
  }
};
</script>
<style>
</style>